import axios from 'axios';
import { fromJS } from 'immutable';
import * as types from './actionTypes';
const showSearchItem = 6;
const getHeaderList = (data) => ({
    type: types.GET_HEADER_LIST,
    data: fromJS(data),
    totalPage: Math.ceil(data.length / showSearchItem)
});

export const getInputFocusValue = () => ({
    type: types.HANDLE_INPUT_FOCUS
});

export const getInputBlurValue = () => ({
    type: types.HANDLE_INPUT_BLUR
});

export const setMouseEnter = () => ({
    type: types.MOUSE_ENTER_IN
});

export const setMouseLeave = () => ({
    type: types.MOUSE_LEAVE
});

export const setAddPage = (page) => ({
    type: types.HANDLE_PAGE,
    page
});

export const asyncHeaderList = () => {
  return (dispatch) => {
      axios.get("/api/header/header.json").then(res => {
          if (res.data.code === 200) {
              const data = res.data.data;
              dispatch(getHeaderList(data));
          }
      })
      .catch(() => {
          console.log('响应失败');
      })
  }
};